package com.tuyrt.firstcode.kotlin.basic

/**
 * Created by tuyrt7 on 2021/4/6.
 * 类、接口
 */

open class Person(val name: String, val age: Int)

class Student(name: String, age: Int, val studentNumber: String) : Person(name, age), Study {

    //次构造函数一定调用主构造
    constructor(name: String, age: Int) : this(name, age, "xxxxxx")

    constructor() : this("xx", 0)

    init {
        //do sth init..
    }

    /** 实现接口中方法 */

    override fun study() {
        println("student study")
    }

    override fun doWork() {
        println("student work")
    }
}

/** 接口 */
interface Study {
    fun study()
    fun doWork()
}

/** 类中关键字：
private: 仅对当前类内部可见
protected: 对当前类及其子类可见
internal: 模块内可见（开发SDK，lib库时使用）
 */

//数据类
data class Phone(val number: String)

//单例
object SingleTon {
    //静态方法
    @JvmStatic
    fun staticDoSth() {
    }
}

class Utils {
    fun doSomething() {}

    companion object {
        //静态方法
        @JvmStatic
        fun staticDoSth() {
        }
    }
}

//密封类
sealed class Car {
    object RedCar : Car()
    object GreenCar : Car()
}